package com.github.soiff.shadow.plugin.helper;

import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Soiff on 2016/05/20.
 *
 * @author : Soiff
 */
public class StringHelper implements Helper<String> {
    @Override
    public CharSequence apply(String regEx, Options options) throws IOException {
        Pattern pat = Pattern.compile(regEx);
        Matcher mat = pat.matcher((String)options.param(0));
        return mat.find()?options.fn():options.inverse();
    }
}
